package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo9 {
	public static void main(String[] args) {
		try (Connection connection = DBUtil.getConnection()){
			connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
			connection.setAutoCommit(false);
			String sql = "Insert into user(username,password,nickname,age)" +
					"values(?,?,?,?)";
		
			PreparedStatement preparedStatement = connection.prepareStatement(sql);
			preparedStatement.setString(1, "admin");
			preparedStatement.setString(2, "123123");
			preparedStatement.setString(3, "管理员");
			preparedStatement.setInt(4, 18);
			int num = preparedStatement.executeUpdate();
			System.out.println(num > 0 ? "添加成功" : "添加失败");
			connection.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
